<?php

namespace App\Models;

use Cog\Contracts\Love\Likeable\Models\Likeable as LikeableContract;
use Cog\Contracts\Love\Liker\Models\Liker as LikerContract;
use Cog\Laravel\Love\Likeable\Models\Traits\Likeable;
use Cog\Laravel\Love\Liker\Models\Traits\Liker;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

/**
 * Class Repository
 *
 * @package App\Models
 *
 * @method Builder indexQuery()
 * @method Builder detailQuery()
 */
class User extends Authenticatable implements LikerContract, LikeableContract
{
    use Notifiable;
    use Liker;
    use Likeable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'email', 'password',];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = ['email', 'email_verified_at', 'password', 'remember_token', 'created_at', 'updated_at'];

    protected $appends = [];

    public function chapters()
    {
        return $this->hasMany(Chapter::class);
    }

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }

    public function repositories()
    {
        return $this->hasMany(Repository::class);
    }

    public function reward()
    {
        return $this->hasOne(UserReward::class);
    }

    public function scopeIndexQuery($query)
    {
        return $query->withCount(['repositories', 'chapters', 'comments']);
    }

    public function scopeDetailQuery($query)
    {
        return $query->indexQuery()->with(['reward']);
    }
}
